package cn.gongxi.weibo.config;

import cn.gongxi.weibo.interceptors.LoginCheckInterceptor;
import cn.gongxi.weibo.interceptors.MyInterceptors1;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration

public class InterceptorsConfig implements WebMvcConfigurer {

    // 三个拦截重写
    public void addInterceptors(InterceptorRegistry registry) {

        // 拦截所有请求
//        registry.addInterceptor(new MyInterceptors1());

        // 拦截微博模块发布微博和发布评论是否登录
        registry.addInterceptor(new LoginCheckInterceptor())
                .addPathPatterns("/v1/weibo/insert","/v1/comment/insert");

        // 拦截评论模块除了/v1/comment/selectByWeiboId之外的所有请求
        registry.addInterceptor(new MyInterceptors1())
                .addPathPatterns("/v1/comment/**")
                .excludePathPatterns("/v1/comment/selectByWeiboId");
    }

}
